func canFinish(numCourses int, prerequisites [][]int) bool {
    g := make([]map[int]bool, numCourses)
    for i := 0; i < numCourses; i++ {
        g[i] = make(map[int]bool)
    }
    indegrees := make([]int, numCourses)
    for _, prerequisite := range prerequisites {
        w := prerequisite[0]
        v := prerequisite[1]
        g[v][w] = true
        indegrees[w]++
    }
    queue := make([]int, 0)
    for i := 0; i < numCourses; i++ {
        if indegrees[i] == 0 {
            queue = append(queue, i)
        }
    }
    index := 0
    for len(queue) > 0 {
        v := queue[0]
        queue = queue[1:]
        index++
        for w := range g[v] {
            indegrees[w]--
            if indegrees[w] == 0 {
                queue = append(queue, w)
            }
        }
    }
    return index == numCourses
}